#include <gtkmm/drawingarea.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <cairomm/context.h>
#include <iostream>
class MyArea : public Gtk::DrawingArea
{
public:
    MyArea();
    virtual ~MyArea();
protected:
//Override default signal handler:
    virtual bool on_expose_event(GdkEventExpose* event);
    virtual bool  on_button_press_event (GdkEventButton* event);
private:
    Cairo::RefPtr<Cairo::Context> cr_;

};
MyArea::MyArea()
{
    add_events(Gdk::BUTTON_PRESS_MASK);
}
MyArea::~MyArea()
{
}
bool MyArea::on_button_press_event(GdkEventButton* event)
{
    if(!cr_){
        Glib::RefPtr<Gdk::Window> window = get_window();
        cr_ = window->create_cairo_context();
    }
    cr_->move_to(0, 0);
    cr_->line_to(event->x, event->y);
    cr_->stroke();
}

bool MyArea::on_expose_event(GdkEventExpose* event)
{
    Glib::RefPtr<Gdk::Window> window = get_window();
    Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
    cr->set_line_width(10.0);
    cr->move_to(0, 0);
    cr->line_to(100, 100);
    cr->stroke();    
    return true;
}
int main(int argc, char** argv)
{
    Gtk::Main kit(argc, argv);
    Gtk::Window win;
    win.set_title("DrawingArea");
    MyArea area;
    win.add(area);
    area.show();
    Gtk::Main::run(win);
    return 0;
}
